package cn.hsa.fqz.task.service.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@NoArgsConstructor
@Data
public class TreeDTO implements Comparable<TreeDTO> {

  protected String id;
  protected String pid;
  protected Integer sort;
  protected String title;
  protected String type;
  protected String path;
  protected String tag;

  protected List<TreeDTO> children = new ArrayList<>();

  public TreeDTO(String treeRootId) {
    this.id = treeRootId;
  }

  public TreeDTO(String id, String pid, String title, String path) {
    this.id = id;
    this.pid = pid;
    this.title = title;
    this.path = path;
  }

  public void setChildren(List<TreeDTO> children) {
    Collections.sort(children);
    this.children = children;
  }

  @Override
  public int compareTo(TreeDTO o) {
    return sort.compareTo(o.getSort());
  }
}
